File: /home/sioberen/public_html/cache/sitemap.php
<?php
header('Content-Type: application/xml; charset=utf-8');
require_once __DIR__ . '/config.php';
try {
$data = getSitemapData();
if (!$data || !isset($data['urls'])) {
throw new Exception("Invalid API response format");
}
$urls = $data['urls'];
$domain = $host;
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
foreach ($urls as $url_data) {
$product_id = $url_data['id'];
$crawled_at = $url_data['crawled_at'];
$product_title = isset($url_data['title']) ? $url_data['title'] : null;
$loc = buildProductUrl($product_id, $product_title);
$lastmod = date('Y-m-d', strtotime($crawled_at));
$xml .= " <url>\n";
$xml .= " <loc>" . htmlspecialchars($loc) . "</loc>\n";
$xml .= " <lastmod>" . htmlspecialchars($lastmod) . "</lastmod>\n";
$xml .= " <changefreq>daily</changefreq>\n";
$xml .= " </url>\n";
}
$xml .= "</urlset>";
echo $xml;
} catch (Exception $e) {
error_log("Sitemap generation error: " . $e->getMessage());
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$xml .= "</urlset>";
echo $xml;
}